/**
 * Created by Administrator on 2016/1/29.
 */
$(function(){

    var countdown=60;
    function settime(obj) {
        if (countdown == 0) {
            obj.removeAttr("disabled");
            obj.val("免费获取验证码");
            countdown = 60;
            return;
        } else {
            obj.attr("disabled", true);
            obj.val("重新发送(" + countdown + ")");
            countdown--;
        }
        setTimeout(function() {
                settime(obj) }
            ,1000)
    }

    $("#sendMsgBtn").click(function(){
        if(!config.loginMsg.mobileNumber){
            CK.alert("手机号码未输入");
            return;
        }


        $.ajax({
            url: CK.formatUrl(config.service.sendMsg),
            data: {
                //userPhone: $("#mobileNumberLogin").val(),
                //userPassword: hex_md5($("#password").val()),
            },
            type: "POST",
            async: true,
            success: function (response) {
                response.status = "true";
                if (response.status == "true") {
                    //使输入框可输入
                    $("#msgCode").removeAttr("disabled");
                    settime( $("#sendMsgBtn"));
                    config.orgId = response.data.orgId;
                    //加载第四步
                    //CK.load("html/login/step4", $("#signContainer"));
                }
            },
        });
    });


    $("#step3Tostep4").click(function(){
        //发送注册信息和短信验证码去后台校验
        $.ajax({
            url: CK.formatUrl(config.service.sendMsg),
            data: {
                //userPhone: $("#mobileNumberLogin").val(),
                //userPassword: hex_md5($("#password").val()),
            },
            type: "POST",
            async: true,
            success: function (response) {
                response.status = "true";
                if (response.status == "true") {

                    //config.orgId = response.data.orgId;
                    //加载第四步
                    CK.load("html/login/step4", $("#signContainer"));
                }
            },
        });
    });
    $("#msgCode").bind('input propertychange', function () {
        //使下一步可以点击
        if($("#msgCode").val().length == 6){
            $("#step3Tostep4").removeClass("disabled");
        }else {
            $("#step3Tostep4").addClass("disabled");
        }
    });


    $("#step2Header").click(function(){

        CK.load("html/login/step2", $("#signContainer"));
    });
    function init(){
        $("#step3Tostep4").addClass("disabled");
        $("#msgCode").attr("disabled","");
    }
    init();

});